import { jsonp } from 'vue-jsonp'


function getAddressLocation(params,analog) {
    return new Promise((resolve, reject) => {
        console.log('getAddressLocation')
        let url = `https://api.map.baidu.com/geocoding/v3/?address=${params}&output=json&ak=S2ywV66oG1QuZnF1u96YLXeb93GamOTy&mcode=4C:E1:B6:FA:C0:0B:23:7B:AB:B7:4F:3D:EE:61:A8:0B:69:76:00:B7;com.ccb.leye`
        if(process.env.DEBUG){
            console.log("================啦啦啦=========>",122)
            jsonp(url).then(res => {           
                console.log('getAddressLocation==============啦啦啦=========>', res, analog);
                let resData = {
                    longitude: res.result.location.lng.toString(),
                    latitude: res.result.location.lat.toString(),
                    result:'1'
                }
                resolve(resData)                     
            }).catch(err=>{
                console.log('getAddressLocation',err,reject)
            }) 
        }else{
            console.log('getAddressLocation url', url)
            jsonp(url).then(res => {           
                console.log('getAddressLocation', res, analog);
                let resData = {
                    longitude: res.result.location.lng.toString(),
                    latitude: res.result.location.lat.toString(),
                    result:'1'
                }
                resolve(resData)                     
            }).catch(err=>{
                console.log('getAddressLocation',err,reject)
            }) 
        }
        
    })
}

export {
    getAddressLocation
}